package com.maochd.cloud.api.file.fallback;

import com.maochd.cloud.api.file.service.RemoteFileService;
import com.maochd.cloud.common.core.constant.CommonConstant;
import com.maochd.cloud.common.core.domain.R;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@Component
public class RemoteFileFallbackFactory implements FallbackFactory<RemoteFileService> {
    @Override
    public RemoteFileService create(Throwable cause) {
        log.error("文件服务调用失败:{}", cause.getMessage());

        return new RemoteFileService() {
            @Override
            public R<String> uploadInner(MultipartFile file, String filename) {
                return R.fail(CommonConstant.EXCEPTION);
            }
        };
    }
}
